﻿using TheLocal.Model;
using TheLocal.ViewModel;
using Windows.UI.Xaml.Controls;

namespace TheLocal.Tablet.Views
{
    public sealed partial class CategoryPage : TheLocal.Tablet.Common.LayoutAwarePage
    {
        CategoryListViewModel categoryListViewModel;

        public CategoryPage()
        {
            this.InitializeComponent();

            categoryListViewModel = ViewModelLocator.CategoryPageViewModel.Categories;

            this.itemGridView.ItemsSource = categoryListViewModel;
            this.itemListView.ItemsSource = categoryListViewModel;
        }

        private ViewModelLocator ViewModelLocator
        {
            get
            {
                return (App.Current as App).ViewModelLocator;
            }
        }

        private void Category_ItemClick(object sender, ItemClickEventArgs e)
        {
            categoryListViewModel.SelectedCategory = e.ClickedItem as Category;
            ViewModelLocator.NewsPageViewModel.SelectedCategory = categoryListViewModel.SelectedCategory;
            this.Frame.Navigate(typeof(NewsPage), null);
        }
    }
}
